function [r, theta] = cellPosPolar(radVector, TwoCellVector)
% FUNCTION [R, THETA] = CELLPOSPOLAR(RAD, TWOCELLVECTOR) calculates the
% distance between cells R and the angle between RAD vector and
% TWOCELLVECTOR.
% written by Taro Kiritani, tarokiritani2008@u.northwestern.edu

r = norm(TwoCellVector);

% calculate the inner product and then the argument.
theta = dot(TwoCellVector, radVector) / (norm(radVector) * r);
theta = acos(theta);

% calculate the cross product of radVector and TwoCellVector. If
% the cross product points upward, theta should be negative?
directionFlag = cross(radVector,TwoCellVector);
theta = sign(directionFlag(:,3)) .* theta;